import anluac.base122 as base122



SAMPLES = (
    ("hello world!", bytes([52,25,45,70,99,60,64,119,55,215,141,70,33,4])),
    ("мир привет!", bytes([104,47,26,11,70,70,194,160,104,47,122,24,6,66,113,80,89,52,22,93,12,8,66])),
)


def test_bytes_encode ():
    for v in SAMPLES:
        textstr, basedbytes = v
        encodedbytes = base122.encode( textstr )
        assert (encodedbytes == basedbytes)


def test_bytes_decode ():
    for v in SAMPLES:
        textstr, basedbytes = v
        decodedbytes = base122.decode( basedbytes )
        decodedstr = decodedbytes.decode( 'utf8' )
        assert (decodedstr == textstr)


def test_bytes_roundtrip ():
    for v in SAMPLES:
        textstr, basedbytes = v
        decodedbytes = base122.decode( base122.encode(textstr) )
        decodedstr = decodedbytes.decode( 'utf8' )
        assert (decodedstr == textstr)


def test_str_encode ():
    for v in SAMPLES:
        textstr, basedbytes = v
        basedstr = basedbytes.decode( 'utf8' )
        encodedstr = base122.encode_as_str( textstr )
        assert (encodedstr == basedstr)


def test_str_decode ():
    for v in SAMPLES:
        textstr, basedbytes = v
        decodedstr = base122.decode_as_str( basedbytes )
        assert (decodedstr == textstr)


def test_str_roundtrip ():
    for v in SAMPLES:
        textstr, basedbytes = v
        decodedstr = base122.decode_as_str( base122.encode(textstr) )
        assert (decodedstr == textstr)
